package com.fast.fastenjoy.base.dao.sqltemplate.transformer;

import java.util.List;

import com.fast.fastenjoy.base.utils.BeanExUtils;

@SuppressWarnings("rawtypes")
public class SqlMapResultTransformer extends ResultTransformerEx{
	
	private static final long serialVersionUID = -7895204563087867790L;
	
	public SqlMapResultTransformer(Class<?> entityClass){
		super(entityClass);
	}
	
	public List transformList(List list) {
		return list;
	}

	public Object transformTuple(Object[] objs, String[] colNames) {
		
		Object obj = null;
		
		try {
			
			obj = entityClass.newInstance();
			
			if(objs != null && objs.length > 0){
				for(int i = 0,len = colNames.length; i < len; i++){
					try{
						String name = colNames[i];
						Object value = objs[i];
						BeanExUtils.setProperty(obj, name, value);
					}catch(Exception ec){
						ec.printStackTrace();
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		} 
		
		return obj;
	}
	
}
